<?php
/**
 * 获取公告数据接口
 * @文件名称: GetShowListAction.php
 * @author: jawei
 * @Email: gaozhiwei@etcp.cn
 * @Date: 2017-06-06
 * @Copyright: 2017 悦畅科技有限公司. All rights reserved.
 * 注意：本内容仅限于悦畅科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
namespace app\modules\common\actions\announcement;

use app\base\BaseService;
use app\components\DmpUtil;
use app\modules\common\models\common\AnnouncementModel;
use app\modules\common\services\common\AnnouncementService;
use yii\base\Action;
use yii;

class GetShowListAction extends Action {
    public function run() {
        $p = (int)Yii::$app->request->post('p', 0);
        $size = (int)Yii::$app->request->post('size', 1);
        $pageSize = DmpUtil::getPageSize($size);
        $offset = DmpUtil::getOffsetNum($p, $size);
        $params['status'] = AnnouncementModel::STATUS_PUBLIC;
        $params['isshow'] = AnnouncementModel::IS_SHOW;
        $ret = AnnouncementService::getShowList($params, $offset, $pageSize);
        if(BaseService::checkRetIsOk($ret)) {
            $result = json_decode($ret, true);
            $totalRet = AnnouncementService::getTotalLine($params);
            if(BaseService::checkRetIsOk($totalRet)) {
                $totalResult = json_decode($totalRet, true);
                $result['total'] = ceil($totalResult['data']/$pageSize);
            }
            return json_encode($result);
        }
        return BaseService::returnErrData([], 500, '请求数据不存在');
    }
}